﻿using Microsoft.AspNetCore.Authorization;

namespace CustomIAuthorizationPolicyProvider.Authorization
{
    public class MinimumAgeAuthorizeAttribute : AuthorizeAttribute
    {
        const string PolicyPrefix = "MinimumAge";
        public MinimumAgeAuthorizeAttribute(int minimumAge)
        {
            Age = minimumAge;
        }
        public int Age
        {
            get
            {
                if (int.TryParse(Policy.AsSpan(PolicyPrefix.Length), out var age))
                {
                    return age;
                }
                return default;
            }
            set
            {
                Policy = $"{PolicyPrefix}{value}";
            }
        }
    }
}
